package com.mini.es.model;

import com.mini.common.EncryptField;
import com.mini.mysql.model.BusinessStudentBigLessonXcx;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.annotation.Id;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.Objects;

import static com.mini.mysql.model.BusinessStudentBigLessonXcx.OrderDeposiType.*;
import static com.mini.mysql.model.BusinessStudentBigLessonXcx.OrderSourceType.OFFLINE;
import static com.mini.mysql.model.BusinessStudentBigLessonXcx.OrderSourceType.ONLINE;
import static com.mini.mysql.model.BusinessStudentBigLessonXcx.OrderState.PAY_FINISH;
import static com.mini.mysql.model.BusinessStudentBigLessonXcx.OrderState.PAY_REFUND_SUCCESS;

@Slf4j
@ApiModel(value = "大课订单-小程序订单表")
@Data
@Builder
@FieldNameConstants
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = EsBusinessStudentBigLessonXcx.index)
public class EsBusinessStudentBigLessonXcx implements Serializable {
    public static final String index = "bussiness_student_big_lesson";
    private static final long serialVersionUID = 5265755800040122821L;

    @Id
    private String orderNo;

    @ApiModelProperty(value = "手机号")
    @EncryptField
    private String phoneNumber;

    @ApiModelProperty(value = "匹配到的小课订单的小课站点")
    private Long lessonSiteId;
    @ApiModelProperty(value = "匹配到的小课订单编号，冗余字段，方便查询使用")
    private String miniOrderNo;

    private Long lessonId;
    @ApiModelProperty(value = "小课订单表中的lessonId")
    private String orderLessonId;
    @ApiModelProperty(value = "大课课程名称")
    private String lessonName;

    private String teachPlanId;

    private String teachPlanName;

    private String skuCode;

    private String skuName;

    @ApiModelProperty(value = "订单生成时间")
    @Field(type = FieldType.Date)
    private Date orderCreateTime;

    @ApiModelProperty(value = "支付发起时间")
    private Date payStartTime;

    @ApiModelProperty(value = "支付完成时间")
    private Date payFinishTime;
    @ApiModelProperty(value = "订单状态：5/15/25")
    private String orderState;
    //使用a_id,b_id这种形式,[,]前不要带空格。。。
//    @Excel(name = "小程序大课订单状态_bigLessonOrderXcx,有赞大课订单状态_bigLessonOrderYouzan",
//            orderNum = "24_bigLessonOrderXcx,26_bigLessonOrderYouzan")
    @ApiModelProperty(value = "订单状态name")
    private String orderStateStr;
    @ApiModelProperty(value = "商品价格")
    private Float price;

    @ApiModelProperty(value = "支付金额")
    private Float payAmount;
    @ApiModelProperty(value = "优惠金额")
    private Float couponAmount;
    @ApiModelProperty(value = "用户昵称")
    private String username;
    @ApiModelProperty(value = "优惠码")
    private String couponCode;

    @ApiModelProperty(value = "大课成单渠道：0-有赞，1-直播带货")
    private String orderSourceType;

    private String remark;

    private Integer orderDepositType;

    private Integer depositMergeState;

    private String relatedKey;

    private String refOrderNo;

    private Integer installmentNum;
    private Date refundTime;

    private Float refundAmount;

    private String refundStatus;

    private String changeClassStatus;

    private String changeClassStatusName;

    private String changeClassRelatedKey;

    @Field(type = FieldType.Date)
    private Date createTime;
    @Field(type = FieldType.Date)
    private Date updateTime;
    @Field(type = FieldType.Date)
    private Date bigLessUpdateTime;

    @Field(type = FieldType.Date)
    private Date secondOrderUpdateTime;

    @Field(type = FieldType.Date)
    private Date deptUpdateTime;

    private String sku;

    private String workRoom;

    private String od;

    private String og;

    private BigInteger teacherId;

    private Integer bindState;

    @ApiModelProperty(value = "备注信息-运营人员编辑")
    private String operateRemark;

    @ApiModelProperty(value = "流水归属：0-默认，1-一阶，2-2阶段")
    private Integer operationStage;
    @ApiModelProperty(value = "二阶机会id")
    private Long secondOrderId;


    /**
     * 以下内容全部来自对象EsBusinessStudentOrderInfo中，以后对EsBusinessStudentOrderInfo的修改需保持一致，个别重名字段进行了重命名或删除
     **/

//    private String miniOrderNo;

    @ApiModelProperty(value = "组id")
    private BigInteger groupId;

    @Field(type = FieldType.Date)
    private Date addWechatTime;
    /**
     * 是否加微信了依赖addWechatTime，1加了 0未加
     */
    private Integer wechatCount;

    @ApiModelProperty(value = "加群状态 0未加 1已加")
    private Integer addWechatGroupState;

    private Date admissionTestTime;

    /**
     * 依赖admissionTestTime，1是 0否
     */
    private Integer testCount;

    private Integer bigLessonNumThisWeek;

    private Integer bigLessonNumOtherWeek;

    private Float orderExpense;

    private Float orderPrice;

    private Float orderCost;

    private Float bigLessonFlowThisWeek;

    private Float bigLessonFlowOtherWeek;

    private Integer bigLessonRefundNum;

    private Float bigLessonRefundAmount;

    @Field(type = FieldType.Date)
    private Date orderUpdateTime;

    @Field(type = FieldType.Date)
    private Date attachUpdateTime;

    @Field(type = FieldType.Date)
    private Date teacherUpdateTime;

    @Field(type = FieldType.Date)
    private Date classUpdateTime;

    @Field(type = FieldType.Date)
    private Date baseUpdateTime;

    @Field(type = FieldType.Date)
    private Date miniUpdateTime;

    @Field(type = FieldType.Date)
    private Date mysqlUpdateTime;

    @ApiModelProperty(value = "运营专员id")
    private BigInteger miniTeacherId;

    @ApiModelProperty(value = "运营专员名称")
    private BigInteger teacherName;

    @ApiModelProperty(value = "业务线，0加盐业务线 1集团业务线")
    private Integer businessType;

    @ApiModelProperty(value = "课程id")
    private String miniLessonId;

    @ApiModelProperty(value = "状态 1未加 2已加 ")
    private Integer states;

    @ApiModelProperty(value = "订单时间")
    @Field(type = FieldType.Date)
    private Date orderPayTime;

    @ApiModelProperty(value = "机会状态 0-正常 1-取消订单 2-未关联(关联取消) 3-未关联(续报取消)")
    private Integer chanceStates;

    @ApiModelProperty(value = "[20201214]续报类型：二阶类型：1-续报专用，2-流量复用，3-拉新裂变（转介绍）")
    private Integer continueType;

    @ApiModelProperty(value = "二阶运营老师id")
    private Long secondTeacherId;

    @ApiModelProperty(value = "二阶运营老师名称")
    private String secondTeacherName;
    /**
     * 2021-03-16 新增
     **/
    @ApiModelProperty(value = "是否使用优惠券 0未使用 1使用")
    private Integer getCoupon;

    @ApiModelProperty(value = "订单时间")
    private Date getCouponTime;

    @ApiModelProperty(value = "公众号关注标识 0未关注 1已关注")
    private Integer followPublic;

    @ApiModelProperty(value = "关注时间")
    private Date followPublicTime;

    @ApiModelProperty(value = "20200710增加 未支付0元单标识 0默认已支付 1未支付")
    private Integer unPayZeroState;


    /**
     * 2021-03-16 新增出勤
     **/
    @ApiModelProperty(value = "[出勤]orderNo")
    private String classOrderNo;

    @ApiModelProperty(value = "[出勤]出勤课节数-总")
    private Integer attnCount;

    @ApiModelProperty(value = "[出勤]出勤课节数-总-是否出勤 0否1是")
    private Integer attnCountExp;

    @ApiModelProperty(value = "[出勤]出勤课节数-直播")
    private Integer attnLiveCount;

    @ApiModelProperty(value = "[出勤]出勤课节数-直播-是否出勤 0否1是")
    private Integer attnLiveCountExp;

    @ApiModelProperty(value = "[出勤]出勤课节数-点播")
    private Integer attnVodCount;

    @ApiModelProperty(value = "[出勤]出勤课节数-点播-是否出勤 0否1是")
    private Integer attnVodCountExp;

    @ApiModelProperty(value = "[出勤]完课课节数-直播")
    private Integer finishLiveCount;

    @ApiModelProperty(value = "[出勤]直播是否完课-0否1是")
    private Integer finishLiveCountExp;

    @ApiModelProperty(value = "[出勤]完课课节数-总")
    private Integer finishCount;


    @ApiModelProperty(value = "[出勤]是否全部完课-0否1是")
    private Integer finishCountExp;

    @ApiModelProperty(value = "[出勤]班次下的课节数-总")
    private Integer classCourseCount;


    @ApiModelProperty(value = "[出勤]班次下的所有课节时长总和")
    private BigInteger classCourseDuration;

    @ApiModelProperty(value = "[出勤]直播时长")
    private BigInteger durationLiveCount;

    @ApiModelProperty(value = "[出勤]直播或点播时长（单个课节取时间长的算）")
    private BigInteger durationCount;

    @ApiModelProperty(value = "工作室id", required = true)
    private BigInteger workRoomId;

    @ApiModelProperty(value = "工作室名称", required = true)
    private String workRoomName;

    @ApiModelProperty(value = "渠道标识")
    private String channelCode;

    @ApiModelProperty(value = "渠道名称")
    private String channelName;

    @ApiModelProperty(value = "负责人id")
    private BigInteger fzId;

    @ApiModelProperty(value = "负责人名称")
    private String fzName;

    @ApiModelProperty(value = "小课订单手机号")
    @EncryptField
    private String phoneNo;

    @ApiModelProperty(value = "微信id")
    private String wxId;

    @ApiModelProperty(value = "学员id")
    private String userId;

    @ApiModelProperty(value = "姓名")
    private String nickName;

    @ApiModelProperty(value = "微信昵称")
    private String wechatName;

    @ApiModelProperty(value = "微信备注昵称")
    private String wechatNameNote;

    @ApiModelProperty(value = "课程标题")
    private String lessonTitle;

    @ApiModelProperty(value = "0-传统订单/1-BF订单")
    private Integer orderChannelType;

    /**
     * 部门相关
     */
    private Long pid;

    private Long u1DeptLevel3Id;

    private Long u2DeptLevel3Id;

    private Long u1Sku;

    private Long u2Sku;

    private Long u1WorkRoom;

    private Long u2WorkRoom;

    private Long u1Od;

    private Long u2Od;

    private Long u1Og;

    private Long u2Og;
    /**
     * 统计扩展字段，方便统计
     **/
    private Float xcxFee;

    private Integer xcxCount;

    private Float xcxRefundFee;

    //一阶
    private Float youzanFee;

    //二阶
    private Float secYouzanFee;

    private Integer youzanCount;

    private Float youzanRefundFee;

    private Float bigLessonRefundFee;

    private Float bigLessonPrice;

    private Integer bigLessonCount;

    private Float bigLessonPriceTotal;

    private Integer bigLessonDepositCount;

    private Integer statesCount;

    private Integer unRefBigLessonCount;

    private Float unRefBigLessonPrice;

    private Integer unRefXcxCount;

    private Float unRefXcxFee;

    private Integer unRefYouzanCount;

    private Float unRefYouzanFee;

    private Float unRefBigLessonPriceTotal;

    private Integer unRefBigLessonDepositCount;

    private Integer secBigLessonCount;

    private Integer secBigLessonDepositCount;

    private Float secBigLessonPrice;

    private Float secBigLessonPriceTotal;

    private Float secBigLessonRefundFee;

    private Float secYouzanRefundFee;

    private Integer secXcxCount;

    private Float secXcxFee;

    private Float secXcxRefundFee;

    private void xcxFeeCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && ONLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))) {
            this.xcxFee = this.payAmount;
        } else {
            this.xcxFee = 0f;
        }
    }

    private void xcxCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState) && ONLINE.getCode().equals(this.orderSourceType) && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)) {
            this.xcxCount = 1;
        } else {
            this.xcxCount = null;
        }
    }

    private void xcxRefundFeeCompute() {
        if (PAY_REFUND_SUCCESS.getState().equals(this.orderState) && ONLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)) || (ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))) {
            this.xcxRefundFee = this.payAmount;
        } else {
            this.xcxRefundFee = 0f;
        }
    }

    private void youzanFeeCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && OFFLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || (ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState))
                && Integer.valueOf(1).equals(this.operationStage)) {
            this.youzanFee = this.payAmount;
        } else {
            this.youzanFee = 0f;
        }
    }

    private void secYouzanFeeCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && OFFLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || (ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState))) {
            if (Integer.valueOf(2).equals(this.operationStage) && Integer.valueOf(0).equals(this.chanceStates)) {
                this.secYouzanFee = this.payAmount;
            }
        }
    }

    private void youzanCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && OFFLINE.getCode().equals(this.orderSourceType)
                && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)) {
            this.youzanCount = 1;
        } else {
            this.youzanCount = 0;
        }
    }

    private void unRefYouzanCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && OFFLINE.getCode().equals(this.orderSourceType)
                && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)
                && Integer.valueOf(0).equals(this.operationStage)) {
            this.unRefYouzanCount = 1;
        } else {
            this.unRefYouzanCount = 0;
        }
    }

    private void bigLessonPriceCompute() {
        if ("20210322120644106nMblYubVX7".equals(this.getOrderNo())) {
            log.info("", "");
        }
        if (PAY_FINISH.getState().equals(this.orderState)
                && (ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))) {
            if (Integer.valueOf(1).equals(this.operationStage) && Integer.valueOf(0).equals(this.businessType)) {
                this.bigLessonPrice = this.payAmount;
            }
        }
    }

    private void secBigLessonPriceCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && (ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))) {
            if (Integer.valueOf(2).equals(this.operationStage) && Integer.valueOf(0).equals(this.chanceStates)) {
                this.secBigLessonPrice = this.payAmount;
                this.secBigLessonCount = 1;
                this.secBigLessonPriceTotal = this.secBigLessonPrice;
            }
        }
    }

    private void bigLessonRefundFeeCompute() {
        if (PAY_REFUND_SUCCESS.getState().equals(this.orderState)) {
            this.bigLessonRefundFee = this.payAmount;
        } else {
            this.bigLessonRefundFee = 0f;
        }
    }

    private void youzanRefundFeeCompute() {
        if (PAY_REFUND_SUCCESS.getState().equals(this.orderState) && OFFLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || (ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState))) {
            this.youzanRefundFee = this.payAmount;
        } else {
            this.youzanRefundFee = 0f;
        }
    }

    private void bigLessonCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState) && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)) {
            this.bigLessonCount = 1;
        } else {
            this.bigLessonCount = null;
        }
    }


    private void bigLessonPriceTotalCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && Integer.valueOf(0).equals(this.operationStage)
                && Objects.nonNull(this.teacherId)
        ) {
            this.bigLessonPriceTotal = this.payAmount;
        } else if (Integer.valueOf(0).equals(this.businessType)
                && PAY_FINISH.getState().equals(this.orderState)
                && Integer.valueOf(1).equals(this.operationStage)
                && Objects.nonNull(this.teacherId)) {
            this.bigLessonPriceTotal = this.payAmount;
        } else {
            this.bigLessonPriceTotal = 0f;
        }
    }

    private void bigLessonDepositCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState) && ORDER_PDEPOSIT.getType().equals(this.orderDepositType)) {
            this.bigLessonCount = 1;
        } else {
            this.bigLessonCount = null;
        }
    }

    private void statesCountCompute() {
        if (Integer.valueOf(2).equals(this.states)) {
            this.bigLessonCount = 1;
        } else {
            this.bigLessonCount = null;
        }
    }

    private void unRefBigLessonPriceCompute() {

        if (PAY_FINISH.getState().equals(this.orderState)
                && (ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))) {
            if (Integer.valueOf(0).equals(this.operationStage)) {
                this.unRefBigLessonPrice = this.payAmount;
            } else {
                this.unRefBigLessonPrice = 0f;
            }
        }
    }

    private void unRefBigLessonCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)
                && Objects.nonNull(this.payAmount)
                && this.payAmount > 0f
                && Integer.valueOf(0).equals(this.operationStage)
                && (Objects.isNull(this.sku) || "0".equals(this.sku))) {
            this.bigLessonCount = 1;
            this.unRefBigLessonCount = 1;
//            this.xcxFee = this.payAmount;
//            this.unRefXcxFee = this.payAmount;
        }
    }

    private void unRefXcxFeeCompute() {

        if (PAY_FINISH.getState().equals(this.orderState)
                && ONLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))
        ) {
            if (Integer.valueOf(0).equals(this.operationStage)
                    && (Objects.isNull(this.sku) || "0".equals(this.sku))) {
                this.xcxFee = this.payAmount;
                this.unRefXcxFee = this.payAmount;
            }
        }
    }

    private void unRefBigLessonDepositCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && ORDER_PDEPOSIT.getType().equals(this.orderDepositType)
                && Integer.valueOf(0).equals(this.operationStage)
                && (Objects.isNull(this.sku) || "0".equals(this.sku))) {
            this.unRefBigLessonDepositCount = 1;
            this.bigLessonDepositCount = 1;
        }
    }

    private void unRefXcxCountCompute() {
        if (Integer.valueOf(0).equals(this.operationStage) && PAY_FINISH.getState().equals(this.orderState) && ONLINE.getCode().equals(this.orderSourceType) && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)) {
            this.unRefXcxCount = 1;
        } else {
            this.unRefXcxCount = 0;
        }
    }

    private void unRefYouzanFee() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && OFFLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || ((ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState)))
        ) {
            if (Integer.valueOf(0).equals(this.operationStage)
                    && (Objects.isNull(this.sku) || "0".equals(this.sku))) {
                this.unRefYouzanFee = this.payAmount;
            }
        } else {
            this.unRefYouzanFee = 0f;
        }
    }

    private Integer filterNull(Integer o) {
        if (Objects.isNull(o)) {
            return 0;
        } else {
            return o;
        }
    }

    private Float filterNull(Float o) {
        if (Objects.isNull(o)) {
            return 0f;
        } else {
            return o;
        }
    }


    private void secBigLessonCountCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && !ORDER_PDEPOSIT.getType().equals(this.orderDepositType)
                && Objects.nonNull(this.payAmount)
                && this.payAmount > 0f
                && Integer.valueOf(2).equals(this.operationStage)) {
//            this.secBigLessonCount = 1 + filterNull(this.unRefBigLessonCount);
            this.secBigLessonDepositCount = 1 + filterNull(this.unRefBigLessonDepositCount);
//            this.secBigLessonPrice = filterNull(this.unRefBigLessonPrice) + filterNull(this.payAmount);
//            this.secBigLessonPriceTotal = filterNull(this.bigLessonPriceTotal) + filterNull(this.unRefBigLessonPriceTotal);
            this.secBigLessonRefundFee = filterNull(this.bigLessonRefundFee) + filterNull(this.bigLessonRefundFee);
            this.secYouzanRefundFee = filterNull(this.youzanRefundFee) + filterNull(this.youzanRefundFee);
            this.secXcxRefundFee = filterNull(this.xcxRefundFee) + filterNull(this.xcxRefundFee);
        } else {
            this.secBigLessonDepositCount = this.unRefBigLessonDepositCount;
            this.secBigLessonRefundFee = this.bigLessonRefundFee;
            this.secYouzanRefundFee = this.youzanRefundFee;
//            this.secXcxFee = this.unRefXcxFee;
            this.secXcxRefundFee = this.xcxRefundFee;
        }


    }

//    private void secBigLessonPriceCompute() {
//        unBigLessonPriceCompute();
//        unRefBigLessonCountCompute();
//    }

    public void oneStageData() {
        this.xcxFeeCompute();
        this.xcxCountCompute();
        this.xcxRefundFeeCompute();
        this.youzanFeeCompute();
        this.youzanCountCompute();
        this.youzanRefundFeeCompute();
        this.bigLessonRefundFeeCompute();
        this.bigLessonPriceCompute();
        this.bigLessonCountCompute();
        this.bigLessonPriceTotalCompute();
        this.bigLessonDepositCountCompute();
        this.statesCountCompute();
        this.secBigLessonCountCompute();

    }

    public void unRefData() {
        this.unRefBigLessonCountCompute();
        this.unRefBigLessonDepositCountCompute();
        this.unRefBigLessonPriceCompute();
        this.unRefXcxFeeCompute();
        this.unRefYouzanCountCompute();
        this.unRefXcxCountCompute();
        this.unRefYouzanFee();

        this.secBigLessonPriceCompute();
        this.secXcxFeeCompute();
        this.secYouzanFeeCompute();
    }

    public void secXcxFeeCompute() {
        if (PAY_FINISH.getState().equals(this.orderState)
                && ONLINE.getCode().equals(this.orderSourceType)
                && ((ORDER_NORMAL.getType().equals(this.orderDepositType) || ORDER_BALANCE.getType().equals(this.orderDepositType)))
                || (ORDER_PDEPOSIT.getType().equals(this.orderDepositType) && Integer.valueOf(1).equals(this.depositMergeState))) {
            if (Integer.valueOf(2).equals(this.operationStage) && Integer.valueOf(0).equals(this.chanceStates)) {
                this.secXcxFee = this.payAmount;
                this.secXcxCount = 1;
            }
        }
    }

    public static EsBusinessStudentBigLessonXcx from(BusinessStudentBigLessonXcx b) {

        EsBusinessStudentBigLessonXcx o = Objects.isNull(b) ? null :
                EsBusinessStudentBigLessonXcx.builder()
                        .orderNo(b.getOrderNo())
                        .phoneNumber(b.getPhoneNumber())
                        .lessonSiteId(b.getLessonSiteId())
                        .miniOrderNo(b.getMiniOrderNo())
                        .lessonId(b.getLessonId())
                        .lessonName(b.getLessonName())
                        .teachPlanId(b.getTeachPlanId())
                        .teachPlanName(b.getTeachPlanName())
                        .skuCode(b.getSkuCode())
                        .skuName(b.getSkuName())
                        .orderCreateTime(b.getOrderCreateTime())
                        .payStartTime(b.getPayStartTime())
                        .payFinishTime(b.getPayFinishTime())
                        .orderState(b.getOrderState())
                        .orderStateStr(b.getOrderStateStr())
                        .price(b.getPrice())
                        .payAmount(b.getPayAmount())
                        .couponAmount(b.getCouponAmount())
                        .username(b.getUsername())
                        .couponCode(b.getCouponCode())
                        .orderSourceType(b.getOrderSourceType())
                        .remark(b.getRemark())
                        .orderDepositType(b.getOrderDepositType())
                        .depositMergeState(b.getDepositMergeState())
                        .relatedKey(b.getRelatedKey())
                        .refOrderNo(b.getRefOrderNo())
                        .installmentNum(b.getInstallmentNum())
                        .refundTime(b.getRefundTime())
                        .refundAmount(b.getRefundAmount())
                        .createTime(b.getCreateTime())
//                        .updateTime(b.getUpdateTime())
                        .bigLessUpdateTime(b.getUpdateTime())
                        .sku(b.getSku())
                        .workRoom(b.getWorkRoom())
                        .od(b.getOd())
                        .og(b.getOg())
                        .teacherId(BigInteger.valueOf(Long.parseLong(b.getTeacherId())))
                        .bindState(b.getBindState())
                        .operateRemark(b.getOperateRemark())
                        .operationStage(b.getOperationStage())
                        .secondOrderId(b.getSecondOrderId())
                        .orderChannelType(b.getOrderChannelType())
                        //新增
                        .refundAmount(b.getRefundAmount())
                        .refundStatus(b.getRefundStatus())
                        .changeClassStatus(b.getChangeClassStatus())
                        .changeClassStatusName(b.getChangeClassStatusName())
                        .changeClassRelatedKey(b.getChangeClassRelatedKey())
                        .build();
        return o;

    }


    public void extractMiniOrder(EsBusinessStudentOrderInfo miniOrder) {

        groupId = miniOrder.getGroupId();
        addWechatTime = miniOrder.getAddWechatTime();
        wechatCount = miniOrder.getWechatCount();
        addWechatGroupState = miniOrder.getAddWechatGroupState();
        admissionTestTime = miniOrder.getAdmissionTestTime();
        testCount = miniOrder.getTestCount();
        bigLessonNumThisWeek = miniOrder.getBigLessonNumThisWeek();
        bigLessonNumOtherWeek = miniOrder.getBigLessonNumOtherWeek();
        orderExpense = miniOrder.getOrderExpense();
        orderPrice = miniOrder.getOrderPrice();
        orderCost = miniOrder.getOrderCost();
        bigLessonFlowThisWeek = miniOrder.getBigLessonFlowThisWeek();
        bigLessonFlowOtherWeek = miniOrder.getBigLessonFlowOtherWeek();
        bigLessonRefundNum = miniOrder.getBigLessonRefundNum();
        bigLessonRefundAmount = miniOrder.getBigLessonRefundAmount();
        orderUpdateTime = miniOrder.getOrderUpdateTime();
        attachUpdateTime = miniOrder.getAttachUpdateTime();
        teacherUpdateTime = miniOrder.getTeacherUpdateTime();
        classUpdateTime = miniOrder.getClassUpdateTime();
        miniUpdateTime = miniOrder.getUpdateTime();
        mysqlUpdateTime = miniOrder.getMysqlUpdateTime();
        teacherName = miniOrder.getTeacherName();
        miniTeacherId = miniOrder.getTeacherId();
        businessType = miniOrder.getBusinessType();
        miniLessonId = miniOrder.getMiniLessonId() == null ? "" : miniOrder.getMiniLessonId().toString();
        states = miniOrder.getStates();
        orderPayTime = miniOrder.getOrderPayTime();
        getCoupon = miniOrder.getGetCoupon();
        getCouponTime = miniOrder.getGetCouponTime();
        followPublic = miniOrder.getFollowPublic();
        followPublicTime = miniOrder.getFollowPublicTime();
        unPayZeroState = miniOrder.getUnPayZeroState();
        classOrderNo = miniOrder.getClassOrderNo();
        attnCount = miniOrder.getAttnCount();
        attnCountExp = miniOrder.getAttnCountExp();
        attnLiveCount = miniOrder.getAttnLiveCount();
        attnLiveCountExp = miniOrder.getAttnLiveCountExp();
        attnVodCount = miniOrder.getAttnVodCount();
        attnVodCountExp = miniOrder.getAttnVodCountExp();
        finishLiveCount = miniOrder.getFinishLiveCount();
        finishLiveCountExp = miniOrder.getFinishLiveCountExp();
        finishCount = miniOrder.getFinishCount();
        finishCountExp = miniOrder.getAttnCountExp();
        classCourseCount = miniOrder.getClassCourseCount();
        classCourseDuration = miniOrder.getClassCourseDuration();
        durationLiveCount = miniOrder.getDurationLiveCount();
        durationCount = miniOrder.getDurationCount();
        baseUpdateTime = miniOrder.getBaseUpdateTime();
        workRoomId = miniOrder.getWorkRoomId();
        workRoomName = miniOrder.getWorkRoomName();
        channelCode = miniOrder.getChannelCode();
        channelName = miniOrder.getChannelName();
        phoneNo = miniOrder.getPhoneNo();
        wxId = miniOrder.getWxId();
        userId = miniOrder.getUserId();
        nickName = miniOrder.getNickName();
        wechatName = miniOrder.getWechatName();
        wechatNameNote = miniOrder.getWechatNameNote();
        lessonTitle = miniOrder.getLessonTitle();
        fzId = miniOrder.getFzId();
        fzName = miniOrder.getFzName();
        orderLessonId = miniOrder.getLessonId();
        teacherId = miniOrder.getTeacherId();

    }
}